using System;
using System.Globalization;
using System.Reflection;
using System.Runtime.Serialization;
using ns20;

namespace Newtonsoft.Json.Serialization
{
	public class DefaultSerializationBinder : SerializationBinder
	{
		internal struct Struct28 : IEquatable<Struct28>
		{
			internal readonly string string_0;

			internal readonly string string_1;

			public Struct28(string assemblyName, string typeName)
			{
				string_0 = assemblyName;
				string_1 = typeName;
			}

			public int GetHashCode()
			{
				return ((string_0 != null) ? string_0.GetHashCode() : 0) ^ ((string_1 != null) ? string_1.GetHashCode() : 0);
			}

			public bool Equals(object obj)
			{
				if (!(obj is Struct28))
				{
					return false;
				}
				return Equals((Struct28)obj);
			}

			public bool Equals(Struct28 other)
			{
				if (string_0 == other.string_0)
				{
					return string_1 == other.string_1;
				}
				return false;
			}
		}

		internal static readonly DefaultSerializationBinder defaultSerializationBinder_0 = new DefaultSerializationBinder();

		private readonly Class179<Struct28, Type> class179_0 = new Class179<Struct28, Type>(smethod_0);

		private static Type smethod_0(Struct28 struct28_0)
		{
			string string_ = struct28_0.string_0;
			string string_2 = struct28_0.string_1;
			if (string_ != null)
			{
				Assembly assembly = Assembly.LoadWithPartialName(string_);
				if (assembly == null)
				{
					Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
					Assembly[] array = assemblies;
					foreach (Assembly assembly2 in array)
					{
						if (assembly2.FullName == string_)
						{
							assembly = assembly2;
							break;
						}
					}
				}
				if (assembly == null)
				{
					throw new JsonSerializationException("Could not load assembly '{0}'.".smethod_0(CultureInfo.InvariantCulture, string_));
				}
				Type type = assembly.GetType(string_2);
				if (type == null)
				{
					throw new JsonSerializationException("Could not find type '{0}' in assembly '{1}'.".smethod_1(CultureInfo.InvariantCulture, string_2, assembly.FullName));
				}
				return type;
			}
			return Type.GetType(string_2);
		}

		public override Type BindToType(string assemblyName, string typeName)
		{
			return class179_0.method_0(new Struct28(assemblyName, typeName));
		}

		public override void BindToName(Type serializedType, out string assemblyName, out string typeName)
		{
			assemblyName = serializedType.Assembly.FullName;
			typeName = serializedType.FullName;
		}
	}
}
